/***********************************************************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
* applicable laws, including copyright laws. 
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT.  ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability 
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the 
* following link:
* http://www.renesas.com/disclaimer
*
* Copyright (C) 2012, 2020 Renesas Electronics Corporation. All rights reserved.
***********************************************************************************************************************/

/***********************************************************************************************************************
* File Name    : r_main.c
* Version      : CodeGenerator for RL78/F13 V2.03.06.01 [25 Nov 2020]
* Device(s)    : R5F10AGG
* Tool-Chain   : CA78K0R
* Description  : This file implements main function.
* Creation Date: 2023/8/22
***********************************************************************************************************************/

/***********************************************************************************************************************
Pragma directive
***********************************************************************************************************************/
/* Start user code for pragma. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */

/***********************************************************************************************************************
Includes
***********************************************************************************************************************/
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_port.h"
#include "r_cg_serial.h"
#include "r_cg_timer.h"
/* Start user code for include. Do not edit comment generated here */
#include "delay.h"

/* End user code. Do not edit comment generated here */
#include "r_cg_userdefine.h"

/***********************************************************************************************************************
Global variables and functions
***********************************************************************************************************************/
/* Start user code for global. Do not edit comment generated here */
unsigned char tx_buffer[4]={0x00,0x01,0x03,0x04};   // modify output voltage
unsigned char rx_buffer[4];
unsigned char tx_duallink_buffer[2]={0x10,0x00};    // start deserialization dual-link iic send data
unsigned char tx_frequency_buffer[2]={0x00,0x80};   // modify frequency of switch

/* the enable pin sequence of max96772 to start chip*/
void EnablePinSequenceToStartChip(){
	P8.7=1;
	delay_ms(10);
	P1.3=1;
	delay_ms(10);
	P4.1=1;
	delay_ms(15);
	P9.1=1;
} // EnablePinSequenceToStartChip()


/*enable level sequence*/
void EnableElectricLevelSequence(){
P8.5=1;
delay_ms(65);
P13.0=1;
delay_ms(10);
P9.0=1;
delay_ms(115);
P8.6=1;
} // EnableLevelSequence()


/* enable pin to test the touchpad */
void TestTouchPad(){
	P12.0=1;
	P1.2=1;
	P8.0=0;
} // TestTouchPad()


/* End user code. Do not edit comment generated here */
void R_MAIN_UserInit(void);

/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
    R_MAIN_UserInit();
    /* Start user code. Do not edit comment generated here */
    R_TAU0_Create();
    R_TAU0_Channel0_Start();
    R_SAU1_Create();
    R_IICA0_Create();
    
    /* enable pin sequence to start chip */
    EnablePinSequenceToStartChip();
    
    /* the sequence of power on */
    EnableElectricLevelSequence();
    
    /* Test the touchpad */
    TestTouchPad(); 
    
    /* modify the backlight */
    P1.4=1;
    
    /* spreading switch frequency */
    R_IIC10_Master_Send(0x38,tx_frequency_buffer,2);
        
    //R_IIC10_Master_Send(0x70,tx_buffer,4);
    while (1U)
    {
	/* start deserialization dual-link patten */
        R_IIC10_Master_Send(0x98,tx_duallink_buffer,2);
        
	/* modify output voltage */
	//R_IIC10_Master_Send(0xd6,tx_buffer,4);
       
	delay_ms(1);
    }
    
    /* End user code. Do not edit comment generated here */
}

/***********************************************************************************************************************
* Function Name: R_MAIN_UserInit
* Description  : This function adds user code before implementing main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void R_MAIN_UserInit(void)
{
    /* Start user code. Do not edit comment generated here */
    EI();
    /* End user code. Do not edit comment generated here */
}

/* Start user code for adding. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
